package com.itbaizhan.springbootdemo4;

import com.itbaizhan.springbootdemo4.filter.SecondFilter;
import com.itbaizhan.springbootdemo4.servlet.SecondServlet;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;

@SpringBootConfiguration
// 或 @Configuration
public class FilterConfig {
    //ServletRegistrationBean 可以注册servlet组件，将其放入spring 容器即可注册servlet
    @Bean  //放入到bean容器中
    public FilterRegistrationBean getFilterRegistrationBean(){
        //注册servlet 组件
        FilterRegistrationBean bean = new FilterRegistrationBean(new SecondFilter());
        //添加过滤路径
        bean.addUrlPatterns("/second");
        return bean;

    }
}
